package oop.java0408;

/**
 * 电视机类 有颜色、价格、屏幕大小等属性
 * 有开机，关闭，换台等功能，但是此功能是通过遥控器实现的；
 */

public class TV {
    private String color;
    private int price;
    private int size;
    private String channel;//频道

    public TV() {
    }

    public TV(String color, int price, int size) {
        this.color = color;
        setPrice(price);
        setSize(size);
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        if (price < 0) {
            throw new RuntimeException("价格不能为负数");
        }
        this.price = price;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        if (size < 0) {
            throw new RuntimeException("尺寸不能为负数");
        }
        this.size = size;
    }

    public String getChannel() {
        return channel;
    }

    public void setChannel(String channel) {
        this.channel = channel;
    }

    //开机
    public void turnOn() {
        System.out.println("电视机成功打开");
    }

    //换台
    public void exchange(String newChannel) {
        setChannel(newChannel);
        System.out.println("换台成功,当前频道：" + channel);

    }

    //关机
    public void turnOff() {
        System.out.println("电视机成功关闭");

    }

    @Override
    public String toString() {
        return "电视机信息：\n颜色" + color + "，价格" + price + "元，尺寸" + size + "寸";
    }
}
